package com.zgf.easy.proxy.demo.core;

import com.zgf.easy.proxy.EasyProxy;
import com.zgf.easy.proxy.demo.extend.order.OrderExtendApi;
import com.zgf.easy.proxy.demo.extend.order.mode.OrderReq;
import com.zgf.easy.proxy.demo.extend.order.mode.OrderRes;
import com.zgf.easy.proxy.demo.extend.user.UserExtendApi;
import com.zgf.easy.proxy.demo.extend.user.mode.UserReq;
import com.zgf.easy.proxy.demo.extend.user.mode.UserRes;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.concurrent.Future;

@Slf4j
@Service
public class DemoBizService {

	@Autowired EasyProxy easyProxy;

	@PostConstruct
	public void start() throws Exception {
		TestCall("impla", easyProxy);
		TestCall("implb", easyProxy);
		TestCall("groovy", easyProxy);
	}

	private void TestCall(String identity, EasyProxy easyProxy) throws Exception {
		OrderExtendApi orderApi = easyProxy.getProxy(identity, OrderExtendApi.class);
		OrderReq req = new OrderReq();
		req.setName(identity);
		OrderRes ores = orderApi.getOrder(req);
		log.info("OrderExtendApi-身份{}调用结果{}", identity, ores);
		UserExtendApi userApi = easyProxy.getProxy(identity, UserExtendApi.class);
		UserReq uReq = new UserReq();
		uReq.setName(identity);
		Future<UserRes> future = userApi.getUser(uReq);
		log.info("UserExtendApi(异步)-身份{}调用结果{}", identity, future.get());
	}

}
